﻿using DataSyncCommon.Model;
using Newtonsoft.Json;
using Serilog;
using Serilog.Core;
using System;

namespace DataSyncCommon
{
    public static class LogHelper
    {
        public static Logger logger = null;
        private static object lock1 = new object();
        public static Logger CreateLoger()
        {
            if (logger == null)
            {
                lock (lock1)
                {
                    if (logger == null)
                    {
                        logger = new LoggerConfiguration()
                   .WriteTo.File($"logs\\{DateTime.Now:MMdd}.txt", (Serilog.Events.LogEventLevel)RollingInterval.Day)//写到文本Serilog.Sinks.File
                   .CreateLogger();
                    }
                }
            }
            return logger;
        }

        public static string InDbLog(ba_sup_log log) {
           
            var reqjson = JsonConvert.SerializeObject(log);
            var responseStr = HttpHelper.WebRequestApi(SysConfig.url + "/InsertLog", reqjson, "POST");
            var res = JsonConvert.DeserializeObject<int>(responseStr);
            return res.ToString();
        }
        public static ba_sup_log CreateLogMo(string msg) {
            return new ba_sup_log() {
                NOTE = msg
            };        
        }
    }

}